/*
 * This is written by Lulu Han.
 * E-mail: locomotive_crypto@163.com
 */

#ifndef PPSPD_NET_SERVER_H
#define PPSPD_NET_SERVER_H

#include <string>
#include <vector>
#include <sstream>
#include <boost/asio.hpp>
#include <NTL/ZZ.h>
#include <NTL/RR.h>


// Server
/*Implement to send and receive data by network*/

using namespace boost::asio::ip;
using namespace boost;

class NetServer{
public:
	NetServer(size_t port);
	
	// Wait for a connection from Client
	void accept();
	
	// Send data to Client
	void send(const char* buff, long len);
	void send(const unsigned char* buff, long len);
	void send(long n);
	void send(const NTL::ZZ& n);
	void send(const NTL::RR& n);
	void send(const std::string& str);
	void send(const std::vector<NTL::ZZ>& vzz);
	void send(const std::vector<NTL::RR>& vrr);
	void send(const std::vector<std::vector<NTL::ZZ>>& vvzz);
	
	// Receive data from Client
	void receive(char* buff, long len);
	void receive(unsigned char* buff, long len);
	void receive(long& n);
	void receive(NTL::ZZ& n);
	void receive(NTL::RR& n);
	void receive(std::string& str);
	void receive(std::vector<NTL::ZZ>& vzz);
	void receive(std::vector<NTL::RR>& vrr);
	void receive(std::vector<std::vector<NTL::ZZ>>& vvzz);
	
	// Close socket
	void close();
	void run();
private:
	asio::io_service m_io_service;
	tcp::socket m_socket;
	 tcp::endpoint m_ep;
    tcp::acceptor m_acceptor;
};

#endif // PPSPD_NET_SERVER_H
